from django.db import models


# 商城商品模型
class StoreGoods(models.Model):
    id = models.AutoField(primary_key=True)
    # 商品标题
    goods_title = models.CharField(max_length=256)
    # 搜索关键字
    goods_keyword = models.CharField(max_length=256, default="")
    # 商品图片
    goods_img = models.TextField(null=True)
    # 商品规格
    goods_specification = models.TextField(null=True)
    # 分类id
    type_id = models.IntegerField(null=True)
    # 唯品会
    goods_wph_price = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    goods_wph_link = models.TextField(null=True)
    # 京东
    goods_jd_price = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    goods_jd_link = models.TextField(null=True)
    # 天猫
    goods_tm_price = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    goods_tm_link = models.TextField(null=True)
    # 淘宝
    goods_tb_price = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    goods_tb_link = models.TextField(null=True)
    # 苏宁
    goods_sn_price = models.DecimalField(max_digits=10, decimal_places=2, null=True)
    goods_sn_link = models.TextField(null=True)
    # 是否推荐
    is_recommend = models.BooleanField(default=False)
    # 是否精选
    is_selection = models.BooleanField(default=False)

    def to_dict(self):
        res = {
            'id': self.id,
            'goods_title': self.goods_title,
            'goods_keyword': self.goods_keyword,
            'goods_img': self.goods_img,
            'goods_specification': self.goods_specification,
            'type_id': self.type_id,
            'goods_wph_price': self.goods_wph_price,
            'goods_wph_link': self.goods_wph_link,
            'goods_jd_price': self.goods_jd_price,
            'goods_jd_link': self.goods_jd_link,
            'goods_tm_price': self.goods_tm_price,
            'goods_tm_link': self.goods_tm_link,
            'goods_tb_price': self.goods_tb_price,
            'goods_tb_link': self.goods_tb_link,
            'goods_sn_price': self.goods_sn_price,
            'goods_sn_link': self.goods_sn_link,
            'is_recommend': self.is_recommend,
            'is_selection': self.is_selection,
        }
        return res

    @staticmethod
    def get_fields():
        return [
            {'field': 'id', 'remark': 'id'},
            {'field': 'goods_title', 'remark': '商品名', 'is_query': '1'},
            {'field': 'goods_keyword', 'remark': '商品关键字', 'is_query': '0'},
            {'field': 'goods_img', 'remark': '商品图片', 'type': 'images', 'not_save': '0'},
            {'field': 'goods_specification', 'remark': '商品规格(多个之间用英文逗号隔开)', 'not_save': '1', 'not_table_show': '1'},
            {'field': 'type_id', 'remark': '商品分类', 'type': 'select', 'is_query': '0'},
            {'field': 'goods_wph_price', 'remark': '唯品会价钱', 'not_table_show': '1'},
            {'field': 'goods_wph_link', 'remark': '唯品会链接', 'not_table_show': '1'},
            {'field': 'goods_jd_price', 'remark': '京东价钱', 'not_table_show': '1'},
            {'field': 'goods_jd_link', 'remark': '京东链接', 'not_table_show': '1'},
            {'field': 'goods_tm_price', 'remark': '天猫价钱', 'not_table_show': '1'},
            {'field': 'goods_tm_link', 'remark': '天猫链接', 'not_table_show': '1'},
            {'field': 'goods_tb_price', 'remark': '淘宝价钱', 'not_table_show': '1'},
            {'field': 'goods_tb_link', 'remark': '淘宝链接', 'not_table_show': '1'},
            {'field': 'goods_sn_price', 'remark': '苏宁价钱', 'not_table_show': '1'},
            {'field': 'goods_sn_link', 'remark': '苏宁链接', 'not_table_show': '1'},
            {'field': 'is_recommend', 'remark': '是否推荐', 'type': 'radio'},
            {'field': 'is_selection', 'remark': '是否精选', 'type': 'radio'},
        ]

    class Meta:
        db_table = "store_goods"
        app_label = "models"
